<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>createData()</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="index.html" title="Smarty 3 Manual">
<link rel="up" href="api.functions.html" title="Chapter 14. Smarty Class Methods">
<link rel="prev" href="api.config.load.html" title="configLoad()">
<link rel="next" href="api.create.template.html" title="createTemplate()">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">createData()</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="api.config.load.html">Prev</a> </td>
<th width="60%" align="center">Chapter 14. Smarty Class Methods</th>
<td width="20%" align="right"> <a accesskey="n" href="api.create.template.html">Next</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="refentry" title="createData()">
<a name="api.create.data"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2>Name</h2>
<p>createData() — creates a data object</p>
</div>
<div class="refsect1" title="Description">
<a name="id430805"></a><h2>Description</h2>
<code class="methodsynopsis"><span class="type">string </span><span class="methodname">createData</span>(<span class="methodparam"><span class="type">object </span><span class="parameter">parent</span></span>);</code><br><code class="methodsynopsis"><span class="type">string </span><span class="methodname">createData</span>();</code><p>
   This creates a data object which will hold assigned variables.
    It uses the following parameters:
    </p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>
      <em class="parameter"><code>parent</code></em> is an optional parameter. It is an uplink to the main Smarty object, 
      a another user-created data object or to user-created template object. These objects can be chained.
      Templates can access variables assigned to any of the objects in it's parent chain.
     </p></li></ul></div>
<p>
  </p>
<p>
   Data objects are used to create scopes for assigned variables. They can be used to have
   controll which variables are seen by which templates.
  </p>
<p>
   </p>
<div class="example">
<a name="id431307"></a><p class="title"><b>Example 14.17. createData()</b></p>
<div class="example-contents"><pre class="programlisting">

&lt;?php
include('Smarty.class.php');
$smarty = new Smarty;

// create data object with its private variable scope
$data = $smarty-&gt;createData();

// assign variable to data scope
$data-&gt;assign('foo','bar');

// create template object which will use variables from data object
$tpl = $smarty-&gt;createTemplate('index.tpl',$data);

// display the template
$tpl-&gt;display();
?&gt;

    </pre></div>
</div>
<p><br class="example-break">
  </p>
<p>
   See also
   <a class="link" href="api.display.html" title="display()"><code class="varname">display()</code></a>,
    and
   <a class="link" href="api.create.template.html" title="createTemplate()"><code class="varname">createTemplate()</code></a>,
  </p>
</div>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="api.config.load.html">Prev</a> </td>
<td width="20%" align="center"><a accesskey="u" href="api.functions.html">Up</a></td>
<td width="40%" align="right"> <a accesskey="n" href="api.create.template.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">configLoad() </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> createTemplate()</td>
</tr>
</table>
</div>
</body>
</html>
